/*
 * basestation.h
 *
 *  Created on: 2010-1-29
 *      Author: gavinweng
 */

#ifndef BASESTATION_H
#define BASESTATION_H

#include "networkplanning.h"
#include "channel.h"
#include "user.h"

enum RFState
{
	FULL,
	HALF,
	SLEEP,
	OFF,
};

struct RFProperty
{
	int x;
	int y;
	double height;
	double power[CHANNEL];
	double bandwidth[CHANNEL];
};


class RFUnit
{
public:
	RFUnit(int x = -1, int y = -1, double height = 0.0);
	virtual  ~RFUnit();

	//RF unit property
	double   GetHeight() const;
	int      GetX() const;
	void     SetX(int X);
	int      GetY() const;
	void     SetY(int Y);
	enum RFState GetState() const;
	double   GetPower(int chan) const;
	void     SetPower(int chan, double pow);
	double   GetBandwidth(int chan) const;
	void	 SetBandwidth(int chan, double bw);
	double   GetBand(int chan) const;
	double   GetCapacity() const;
	int      GetChanOrder(int order) const;
	void     SetChanOrder(int order, int chan);


	void     AddUser( int X , int Y);

	virtual void ChanOrder();          //channel filling policy
	virtual void Reset();

	virtual bool   IsOpen() const;
	virtual int    SetOpen(RFState sta = FULL);    //return the served user number when the BS turns on.
	virtual double CalculateBandDemand(const UserProperty& user, int chan) = 0;

	double   CalculatePower(int x, int y, int chan = -1) const; //in dBm
	void     CalculateCapacity();
	void     CalculateUserList();
	void     ReCalculateUserList();
	UserList userlist;       //user list
	double   pathloss[SIZE][SIZE]; //in dB

protected:
	int    x , y;                //position
	double height;               //height

	double power[CHANNEL];       //power(in dBm) of BS
	double bandwidth[CHANNEL];   //bandwidth assigned to the BS

	enum   RFState state;        //RF state

	int    chanOrder[CHANNEL];   //the order according to which channel be filled

//	double AntennaPolicy;

	double band[CHANNEL];        //bandwidth actually used
	double capacity;             //capacity

};

class BaseStation: public RFUnit
{
public:
	BaseStation();
	BaseStation(const RFProperty& bsproperty, int num );
	static int BSNumber;

	bool   IsOpen() const;
//	int    SetOpen(RFState sta = FULL);    //return the served user number when the BS turns on.
	int    GetNumber() const;
	void   ChanOrder();

	double CalculateBandDemand(const UserProperty& user, int chan);
private:
	int    num ;                 //specify base station

};

#endif /* BASESTATION_H */
